import 'package:flutter/material.dart';
import 'package:toastification/toastification.dart';

/// Toast提示组件
/// 提供成功、失败、警告三种提示类型
class ToastNotificationHelper {
  /// 显示成功提示
  static void showSuccessToast(
    BuildContext context, {
    required String message,
    String? title,
    Duration duration = const Duration(seconds: 3),
  }) {
    toastification.show(
      context: context,
      type: ToastificationType.success,
      style: ToastificationStyle.flat,
      title: Text(title ?? 'Success'),
      description: Text(message),
      alignment: Alignment.topRight,
      direction: TextDirection.ltr,
      autoCloseDuration: duration,
      animationDuration: const Duration(milliseconds: 300),
      icon: const Icon(Icons.check_circle, color: Colors.white),
      primaryColor: Colors.green,
      backgroundColor: Colors.green,
      foregroundColor: Colors.white,
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      borderRadius: BorderRadius.circular(12),
      boxShadow: const [
        BoxShadow(
          color: Color(0x07000000),
          blurRadius: 16,
          offset: Offset(0, 16),
          spreadRadius: 0,
        ),
      ],
      showProgressBar: true,
      closeButtonShowType: CloseButtonShowType.onHover,
      closeOnClick: false,
      pauseOnHover: true,
      dragToClose: true,
      applyBlurEffect: true,
      callbacks: ToastificationCallbacks(
        onTap: (toastItem) => print('Toast clicked'),
        onCloseButtonTap: (toastItem) => print('Toast close button tapped'),
        onAutoCompleteCompleted:
            (toastItem) => print('Toast auto complete completed'),
        onDismissed: (toastItem) => print('Toast dismissed'),
      ),
    );
  }

  /// 显示失败提示
  static void showErrorToast(
    BuildContext context, {
    required String message,
    String? title,
    Duration duration = const Duration(seconds: 3),
  }) {
    toastification.show(
      context: context,
      type: ToastificationType.error,
      style: ToastificationStyle.flat,
      title: Text(title ?? 'Error'),
      description: Text(message),
      alignment: Alignment.topRight,
      direction: TextDirection.ltr,
      autoCloseDuration: duration,
      animationDuration: const Duration(milliseconds: 300),
      icon: const Icon(Icons.error, color: Colors.white),
      primaryColor: Colors.red,
      backgroundColor: Colors.red,
      foregroundColor: Colors.white,
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      borderRadius: BorderRadius.circular(12),
      boxShadow: const [
        BoxShadow(
          color: Color(0x07000000),
          blurRadius: 16,
          offset: Offset(0, 16),
          spreadRadius: 0,
        ),
      ],
      showProgressBar: true,
      closeButtonShowType: CloseButtonShowType.onHover,
      closeOnClick: false,
      pauseOnHover: true,
      dragToClose: true,
      applyBlurEffect: true,
      callbacks: ToastificationCallbacks(
        onTap: (toastItem) => print('Toast clicked'),
        onCloseButtonTap: (toastItem) => print('Toast close button tapped'),
        onAutoCompleteCompleted:
            (toastItem) => print('Toast auto complete completed'),
        onDismissed: (toastItem) => print('Toast dismissed'),
      ),
    );
  }

  /// 显示警告提示
  static void showWarningToast(
    BuildContext context, {
    required String message,
    String? title,
    Duration duration = const Duration(seconds: 3),
  }) {
    toastification.show(
      context: context,
      type: ToastificationType.warning,
      style: ToastificationStyle.flat,
      title: Text(title ?? 'Warning'),
      description: Text(message),
      alignment: Alignment.topRight,
      direction: TextDirection.ltr,
      autoCloseDuration: duration,
      animationDuration: const Duration(milliseconds: 300),
      icon: const Icon(Icons.warning, color: Colors.white),
      primaryColor: Colors.orange,
      backgroundColor: Colors.orange,
      foregroundColor: Colors.white,
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      borderRadius: BorderRadius.circular(12),
      boxShadow: const [
        BoxShadow(
          color: Color(0x07000000),
          blurRadius: 16,
          offset: Offset(0, 16),
          spreadRadius: 0,
        ),
      ],
      showProgressBar: true,
      closeButtonShowType: CloseButtonShowType.onHover,
      closeOnClick: false,
      pauseOnHover: true,
      dragToClose: true,
      applyBlurEffect: true,
      callbacks: ToastificationCallbacks(
        onTap: (toastItem) => print('Toast clicked'),
        onCloseButtonTap: (toastItem) => print('Toast close button tapped'),
        onAutoCompleteCompleted:
            (toastItem) => print('Toast auto complete completed'),
        onDismissed: (toastItem) => print('Toast dismissed'),
      ),
    );
  }

  /// 显示信息提示
  static void showInfoToast(
    BuildContext context, {
    required String message,
    String? title,
    Duration duration = const Duration(seconds: 3),
  }) {
    toastification.show(
      context: context,
      type: ToastificationType.info,
      style: ToastificationStyle.flat,
      title: Text(title ?? 'Info'),
      description: Text(message),
      alignment: Alignment.topRight,
      direction: TextDirection.ltr,
      autoCloseDuration: duration,
      animationDuration: const Duration(milliseconds: 300),
      icon: const Icon(Icons.info, color: Colors.white),
      primaryColor: Colors.blue,
      backgroundColor: Colors.blue,
      foregroundColor: Colors.white,
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      borderRadius: BorderRadius.circular(12),
      boxShadow: const [
        BoxShadow(
          color: Color(0x07000000),
          blurRadius: 16,
          offset: Offset(0, 16),
          spreadRadius: 0,
        ),
      ],
      showProgressBar: true,
      closeButtonShowType: CloseButtonShowType.onHover,
      closeOnClick: false,
      pauseOnHover: true,
      dragToClose: true,
      applyBlurEffect: true,
      callbacks: ToastificationCallbacks(
        onTap: (toastItem) => print('Toast clicked'),
        onCloseButtonTap: (toastItem) => print('Toast close button tapped'),
        onAutoCompleteCompleted:
            (toastItem) => print('Toast auto complete completed'),
        onDismissed: (toastItem) => print('Toast dismissed'),
      ),
    );
  }

  /// 清除所有Toast
  static void clearAllToasts(BuildContext context) {
    toastification.dismissAll();
  }
}
